<template>
  <div class="shortmsg-商品配置-set gray-box top-redius border-bottom-gray">
    <div class="title">
      {{ $t('sysManagement.prodConfig') }}
    </div>
    <el-form
      ref="dataFormRef"
      label-width="180px"
      size="default"
      class="set-form"
      label-position="left"
      :model="dataForm"
      @submit.prevent
      @keyup.enter="onSubmit()"
    >
      <el-form-item
        :label="$t('sysManagement.prodAudit')"
        style="width:640px"
        prop="prodAudit"
      >
        <el-switch
          v-model="dataForm.prodAudit"
          active-color="#13ce66"
          inactive-color="#ff4949"
        />
        <el-tooltip
          class="item"
          effect="dark"
          :content="$t('sysManagement.prodAuditTip')"
          placement="top"
        >
          <el-icon><InfoFilled /></el-icon>
        </el-tooltip>
      </el-form-item>
      <el-form-item
        :label="$t('sysManagement.signCategoryAudit')"
        style="width:640px"
        prop="signingAudit"
      >
        <el-switch
          v-model="dataForm.signingAudit"
          active-color="#13ce66"
          inactive-color="#ff4949"
        />
        <el-tooltip
          class="item"
          effect="dark"
          :content="$t('sysManagement.signCategoryAuditTip')"
          placement="top"
        >
          <el-icon><InfoFilled /></el-icon>
        </el-tooltip>
      </el-form-item>
    </el-form>

    <div>
      <div class="dialog-footer">
        <div
          class="default-btn"
          @click="onSubmit(dataFormRef)"
        >
          {{ $t('sysManagement.save') }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ElMessage } from 'element-plus'
const emit = defineEmits(['refreshDataList'])
const dataFormRef = ref(null)
const dataForm = reactive({
  prodAudit: false,
  signingAudit: false
})

onMounted(() => {
  init()
})

const init = () => {
  nextTick(() => {
    http({
      url: http.adornUrl('/sys/pconfig/info/' + 'PROD_SWITCH_CONFIG'),
      method: 'get',
      params: http.adornParams()
    }).then(({ data }) => {
      if (data) {
        data = JSON.parse(data)
        dataForm.prodAudit = data.prodAudit
        dataForm.signingAudit = data.signingAudit
      }
    })
    dataFormRef.value?.resetFields()
  })
}
// 表单提交
const onSubmit = () => {
  http({
    url: http.adornUrl('/sys/audit/save'),
    method: 'post',
    data: http.adornData({
      paramKey: 'PROD_SWITCH_CONFIG',
      paramValue: JSON.stringify({
        prodAudit: dataForm.prodAudit,
        signingAudit: dataForm.signingAudit
      }),
      remark: $t('sysManagement.prodConfig')
    })
  }).then(
    ElMessage({
      message: $t('publics.operation'),
      type: 'success',
      duration: 1500,
      onClose: () => {
        emit('refreshDataList')
      }
    })
  )
}
defineExpose({ init })
</script>
